package src.lab03.test06;

import javafx.scene.shape.Path;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.Map;

public class Test06 {
    public static void main(String[] args) {

        String path="E:\\words.txt";
        RandomAccessFile randomAccessFile=null;
        Map<String,Integer>map=new HashMap<String, Integer>();
        try {
            //打开一个文件
            randomAccessFile=new RandomAccessFile(path,"r");
            String line=null;
            try {
                while ((line=randomAccessFile.readLine())!=null){

                    System.out.println(line);

                    //先判断map中有不有这个单词
                    if(map.get(line)==null){

                        map.put(line,1);

                    }else {
                        //有这个单词怎么做
                        int value=map.get(line);
                        value=value+1;
                        map.put(line,value);
                        System.out.println(map);
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                //关闭文件
                randomAccessFile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
